package com.dyh.quickdemozwei.fieldsDef;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.util.function.BiConsumer;
import java.util.function.Function;

/**
 * @Author: yhdong
 * @Date: 2021/9/6 20:08
 */
//@Builder
@Setter@Getter
@Builder
public class FieldVisitor  {
    String path;
    boolean isLeaf;
    public String filedName;
    public  String parentFiledName = "root";
    public  Class belongNodeClass;
    public Class filedClass;
    public Function getter;
    public BiConsumer setter;

//    public FieldVisitor(Class<N> belongNodeClass, Class<F> filedClass) {
//        this.belongNodeClass = belongNodeClass;
//        this.filedClass = filedClass;
//    }

//    /*help 泛型*/
//    public static <N,F> FieldVisitor<N,F> from(
//            Class<N> belongNodeClass,
//            Class<F> filedClass
//    ){
//        return new FieldVisitor<>(belongNodeClass,filedClass);
//    }

//    public F read(Object belongNode){
//        N ndoe = belongNodeClass.cast(belongNode);
//        F result = getter.apply(ndoe);
//        return result;
//    }

    public static void main(String[] args) {
       // FieldVisitor.builder().belongNodeClass(JSONObject.class).filedClass(Integer.class).getter();

//        JSONObject jo = new JSONObject();
//        jo.put("age", 18);
//
//        Foo foo = new Foo();
//
//
//        FieldVisitor<JSONObject, Integer> visitor1 = FieldVisitor.from(JSONObject.class,
//                Integer.class);
//        visitor1.getter = e->e.getInteger("age");
//        Map<String,FieldVisitor> m1 = new HashMap();
//        m1.put("age",visitor1);
//
////        Integer res = visitor1.read(jo);
//
//        FieldVisitor<Foo, String> visitor2 = FieldVisitor.from(Foo.class,String.class);
//        visitor2.setter=Foo::setAge;
//        Map<String,FieldVisitor> m2 = new HashMap();
//        m2.put("age",visitor2);
//
//        map(jo,m1,foo,m2);
//
//        System.out.println();

    }



}
